

jQuery(function($) {  
	
	$('html').attr('style','overflow-x:scroll;overflow-y:scroll;');
	
    $("#neSel").change(function(){
        var url = _ctx + "/alarm/alarmprop/getUseCardSlot";
        var optionstr = '<option value="0" selected>ALL</option>';
		$.getJSON(url,{neid:$("#neSel").val()},function(data){
			//var json = eval('(' + data + ')');
			for (var i=0; i<data.length; i++){
				optionstr = optionstr + "<option value="+data[i].cardid+">"+data[i].num+":"+data[i].cardtype+"</option>";
			}
			$("#slotSel").html(optionstr);
		});
    });
	
	$("#btn_conf").click(function() {
		var selList = $.find("input[class='ace']:checked");
		var checkedNum = selList.length;
		//console.log(checkedNum);
		if (checkedNum == 0) {
			bootbox.alert("请至少选择一条当前告警信息！", function(result) {});				
			return;
		}
		bootbox.dialog({
			message: "<i class='icon-warning-sign'></i>&nbsp;&nbsp;<span class='bigger-110'>您选择了"+checkedNum+"条当前告警进行确认?</span>",
			buttons: 			
			{
				"info" :
				{
					"label" : "<i class='icon-ok'></i>确认",
					"className" : "btn-success",  
					"callback": function() {
						var checkedList = new Array();
						$(selList).each(function() {
							if($(this).val()!="on"){										
								checkedList.push($(this).val());
							}
						});
						//提交到数据库
						$.ajax({
							type : "GET",
							url : _ctx + "/alarm/alarmcur/confalarm/"+checkedList,
							data : {
								'ids' : checkedList.toString()
							},
							success : function(result) {
								console.log("000"+result);
								if(result==1){
									$("input[class='ace']:checked").attr("checked", false);
									$('#searchForm').submit();
								} else {
									bootbox.alert("告警信息确认失败.", function(result) {});											
								}
							}
						});
					}
				},
				"success" :
				 {
					"label" : "关闭",
					"className" : "btn-danger",
					"callback": function() {
						//Example.show("great success");
					}
				}					
			}
		});		
	});	
	
    $("#btn_sync").click(function(){
        var url = _ctx + "/alarm/alarmcur/cursync";
        $('#searchForm').attr('action',url);       
        $('#searchForm').submit();
    	//var afterFunc = parent.commonAPI.info;
        var afterFunc = $('#searchForm').submit;
		var paramList = ['通知', '测试参数返回正确。'];
		parent.commonAPI.progress(0,'正在进行告警同步操作....', afterFunc, paramList);
    });
    
    $("[name='cerAlarm']").click(function(e){
    	var id = $(e.target).next().text();
    	$('#modalTable').modal('show');
    	$.ajax({type : "GET",
    		url : _ctx + "/alarm/alarmcur/open/"+id,							
    		success : function(data) {
    		var json = eval('(' + data + ')');
    		$("[name^='m_']").each(function(index, item){
    			$(item).val(json[item.name]);
    		});
    	}});    	
    });    
    
	$('table th input:checkbox').on('click',function() {
		var that = this;
		$(this).closest('table').find('tr > td:first-child input:checkbox').each(
				function() {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
	});
});